package br.com.jbssistemas.dirfweb.util;

import java.io.IOException;
import javax.faces.context.FacesContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Daniel
 * 
 */
public class ReportUtil {

    public FacesContext context;
    public HttpServletResponse response;
    public String javaPath;

    public ReportUtil() {
        
        context = FacesContext.getCurrentInstance();

        response = (HttpServletResponse) context.getExternalContext().getResponse();
       
        javaPath = context.getExternalContext().getRealPath("/WEB-INF/report");
        
    }

    public FacesContext getContext() {
        return context;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public String getJavaPath() {
        return javaPath;
    }

    public void mostrarRelatorio(byte[] relatorio, HttpServletResponse response) throws IOException {

        ServletOutputStream out = null;

        try {

            out = response.getOutputStream();

            response.setContentType("application/pdf");

            out.write(relatorio);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.flush();
            out.close();
        }
    }
    
}
